﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;

namespace Wala.Connection.Objects.Profiles
{
    public class ShortProfile
    {
        #region //-------------- Private Fields ------------//

        private uint _uid;
        private string _uname;
        private string _display_name;
        private ulong _avatar_id;
        private ulong _cover_id;
        private uint _gender;
        private string _status;

        //extra
        private bool isfriend = false;
        private string alias_name = ""; //just for friend

        #endregion

        #region //-------------- CLR Properties --------------//

        public uint Uid
        {
            get { return _uid; }
            set { _uid = value; }
        }

        public string Uname
        {
            get { return _uname; }
            set { _uname = value; }
        }

        public string Display_name
        {
            get { return _display_name; }
            set { _display_name = value; }
        }

        public ulong Avatar_id
        {
            get { return _avatar_id; }
            set { _avatar_id = value; }
        }

        public ulong Cover_id
        {
            get { return _cover_id; }
            set { _cover_id = value; }
        }

        public uint Gender
        {
            get { return _gender; }
            set { _gender = value; }
        }

        public string Status
        {
            get { return _status; }
            set { _status = value; }
        }

        #endregion

        #region //------------- Public Constructor -----------//

        public ShortProfile()
        {
            _avatar_id = 0;
            _cover_id = 0;
            _gender = 0;
            _uid = 0;
            _uname = "";
            _display_name = "";
            _status = "";
        }

        public ShortProfile(uint _uid, string _uname, string _display_name, ulong _avatar_id, ulong _cover_id, uint _gender, string _status)
        {
            this._status = _status;
            this._gender = _gender;
            this._cover_id = _cover_id;
            this._avatar_id = _avatar_id;
            this._display_name = _display_name;
            this._uname = _uname;
            this._uid = _uid;
        }

        #endregion

        #region //------------- Public Methods -------------//

        public static ShortProfile FromJson(string json)
        {
            try
            {
                JObject jObject = JObject.Parse(json);
                uint uid = (uint)jObject["uid"];
                string uname = (string)jObject["uname"];
                string displayName = (string)jObject["display_name"];
                ulong avatarID = (ulong)jObject["avatar_id"];
                ulong coverID = (ulong)jObject["cover_id"];
                uint gender = (uint)jObject["gender"];
                string status = (string)jObject["status"];

                return new ShortProfile(uid, uname, displayName, avatarID, coverID, gender, status);
            }
            catch (System.Exception ex)
            {
                return new ShortProfile();
            }

        }

        #endregion
    }
}
